<%!
public class RS
{
	java.sql.Statement stm1=null;
	java.sql.ResultSet rs=null;
	public int colCount=0;
	public RS(java.sql.Statement stm1)
	{
		this.stm1=stm1;
	}
	public String parseXML()
	{
		String str1="";
		int rowid=0;
		StringBuffer re1=new StringBuffer();
		for(int i=1;i<=colCount;i++)
		{
			if(i!=1) re1.append("\t");
			try{
			re1.append(rs.getMetaData().getColumnName(i));
			}catch(Exception e)
			{}
		}//for
		try{
		while(rs.next())
		{
			re1.append("\r\n");
			rowid++;
			for(int i=1;i<=colCount;i++)
			{
			if(i!=1) re1.append("\t");
			str1=rs.getString(i);
			if(str1!=null)
			{
			str1=str1.replaceAll("\\\\","\\\\\\\\").replaceAll("\"","\\\\\"").replaceAll("\t","\\\\\t").replaceAll("\r\n","\\\\r\\\\n").replaceAll("\n","\\\\n");
			re1.append(str1);
			}
			
			}
			
		}
		}catch(Exception e)
		{}
		return re1.toString();
	}
	public void open(String str1) throws Exception
	{
		 this.query(str1);
		
		}
	public void open(String str1,int limit1,int limit2)  throws Exception
	{
		 this.query(str1,limit1,limit2);
		
		}
	public void query(String str1)  throws Exception
	{
		try{
			//System.out.println(str1);
			rs=stm1.executeQuery(str1);
			colCount=rs.getMetaData().getColumnCount();
			
			}
		catch(Exception e)
		{
			rs=null;
			System.out.println(e.toString());
			throw e;
			
			}
	}
	public void query(String str1,int limit1,int limit2)  throws Exception
	{
		try{
			str1+=" limit "+String.valueOf(limit1)+","+String.valueOf(limit2);
			//System.out.println(str1);
			
			rs=stm1.executeQuery(str1);
			colCount=rs.getMetaData().getColumnCount();
			
			}
		catch(Exception e)
		{
			rs=null;
			System.out.println(e.toString());throw e;
			
			}
		}
	public void cmd(String str1)  throws Exception
	{
		try{
			System.out.println(str1);
			stm1.execute(str1);
			
			}
			catch(Exception e)
			{
				System.out.println(e.toString());throw e;
			}
		}
	public boolean next()  throws Exception
	{
		try{
		if(rs!=null)
		{
			return rs.next();
		}else
		{
			return false;		
		}
		}catch(Exception e)
		{throw e;
			}
	}
	public String getString(String str1)  throws Exception
	{
		return this.get(str1);
	}
	public String get(int str1)  throws Exception
	{
		String tmp1;
		try{
		tmp1=rs.getString(str1)==null?"":rs.getString(str1);
		}catch(Exception e)
		{
			throw e;
			}
		return tmp1;
		}
	public String get(String str1)  throws Exception
	{
		String tmp1;
		try{
		tmp1=rs.getString(str1)==null?"":rs.getString(str1);
		}catch(Exception e)
		{
			tmp1=e.toString();
			throw e;
			}
		return tmp1;
		}
	public int getInt(String str1)  throws Exception
	{
		try{
			return rs.getInt(str1);
			}catch(Exception e)
			{
				throw e;
				}
	}
	public String getColName(int i)  throws Exception
	{	try{
		return rs.getMetaData().getColumnName(i);
		}catch(Exception e)
		{
			throw e;
			}
		}
	public void close()  throws Exception
	{
		try{
			stm1.close();
		}catch(Exception e)
		{throw e;}
		}
}//class Stm
public class Conn
{
   public java.sql.Connection conn = null;
   boolean status=false;
   public String err="";
   public Conn() throws Exception
   {
   	try{
  javax.naming.Context ctx=new javax.naming.InitialContext();
	javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/oracle");
	conn=ds.getConnection();
	 	conn.setAutoCommit(false); 
   	status=true;
   	}catch(Exception e)
   {
   	status=false;
   	err=e.toString();
   	throw e;
   } 
	}
   public Conn(String datasource) throws Exception
   {
   
   try{
  javax.naming.Context ctx=new javax.naming.InitialContext();
	javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/"+datasource);
	conn=ds.getConnection();
	 	conn.setAutoCommit(false); 
   	status=true;
   	}catch(Exception e)
   {
   	status=false;
   	err=e.toString();
   	throw e;
   } 
   }//new 
   public RS getRS() throws Exception
   {
   	try{
		return new RS(conn.createStatement());
		}catch(Exception e)
		{
		throw e;
		}
   	}
   public java.sql.Statement createStatement()  throws Exception
	{
		try{
		return conn.createStatement();
		}catch(Exception e)
		{
		throw e;
		}
	}
	public void close()  throws Exception
	{
		try{
		conn.commit(); 
		conn.close();
		status=false;
		}catch(Exception e)
		{throw e;}
	}
	public void commit()  throws Exception
	{
		try{
		conn.commit();
		}catch(Exception e)
		{throw e;}
	}
	public void rollback()  throws Exception
	{
		try{
		conn.rollback();
		}catch(Exception e)
		{throw e;}
	}
}//class sqlca	
